package com.kfyang.manualgear.generator.impl.jdbc.orm;

import com.squareup.javapoet.MethodSpec;
import com.kfyang.manualgear.annotation.comment.MayOverride;
import com.kfyang.manualgear.struct.EntityInfo;

public abstract class AbstractMethod {
    protected MethodSpec.Builder methodBuilder;
    protected EntityInfo entityInfo;
    /**
     * 处理一条还是多条记录
     */
    protected boolean forOne;

    protected AbstractMethod(MethodSpec.Builder methodBuilder, EntityInfo entityInfo, boolean forOne) {
        this.methodBuilder = methodBuilder;
        this.entityInfo = entityInfo;
        this.forOne = forOne;
    }

    public final void generate() {
        prepareParameters();
        prepareSql();
        addReturn();
    }

    /**
     * 准备参数
     */
    @MayOverride
    protected void prepareParameters() {
    }

    /**
     * 准备 sql 语句
     */
    protected abstract void prepareSql();

    /**
     * 返回结果
     */
    protected abstract void addReturn();
}
